package com.zzyy.study.review.container;

import com.zzyy.study.review.enums.PayTypeStrEnum;
import com.zzyy.study.review.strategy.CCBPayTypeParseStrategy;
import com.zzyy.study.review.strategy.PayTypeParseContext;
import com.zzyy.study.review.strategy.PayTypeParseStrategy;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @auther zzyy
 * @create 2024-06-23 15:02
 *
 * 容器化工厂设计模式
 */
@Component
public class PayTypeParseStrategyContainer
{
    public static Map<PayTypeStrEnum, PayTypeParseStrategy> STRATEGY_MAP = new HashMap<>();

    @PostConstruct
    public void init()
    {
        STRATEGY_MAP.put(PayTypeStrEnum.CCB,new CCBPayTypeParseStrategy());
/*        STRATEGY_MAP.put(PayTypeStrEnum.ABC,new CCBPayTypeParseStrategy());
        STRATEGY_MAP.put(PayTypeStrEnum.CB,new CCBPayTypeParseStrategy());
        STRATEGY_MAP.put(PayTypeStrEnum.CCB,new CCBPayTypeParseStrategy());*/
        System.out.println("---inti task over");
    }

    public Integer parse(PayTypeParseContext payTypeParseContext)
    {
        return Optional
                .ofNullable(STRATEGY_MAP.get(payTypeParseContext.getPayTypeParseStrategy()))
                .map(strategy -> strategy.parse(payTypeParseContext))
                .orElse(null);

    }

}
